package cn.qayy.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;


import cn.qayy.constants.CollectionConstant;
import cn.qayy.constants.Constant;
import cn.qayy.service.Uploadable;
import cn.qayy.utils.StringUtil;

/**
 * 
 * 
 * @author wangyu
 * 通讯录DTO 
 * @date 2018-09-03
 */
public class MailListDTO extends commonDTO implements Serializable,Uploadable{
	/**
     * 地区
     */
    private String region;
    
	/**
     * 职位
     */
    private String position;
    /**
     * 姓名
     */
    private String name;

    /**
     * 性别
     */
    private String sex;
    
    /**
     * 座机号码
     */
    private String machineNumber;
    
    /**
     * 手机号
     */
    private String mobilePhone;
    
    /**
     * 邮箱
     */
    private String email;
    
    /**
     * 传真号码
     */
    private String faxNumber;
    
    /**
     * 通讯地址
     */
    private String address;

    /**
	 * 修订标识
	 */
	private String isUpdate = "E";
	
	private String id;
	
	public String getFaxNumber() {
		return faxNumber;
	}

	public void setFaxNumber(String faxNumber) {
		this.faxNumber = faxNumber;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getMobilePhone() {
		return mobilePhone;
	}

	public void setMobilePhone(String mobilePhone) {
		this.mobilePhone = mobilePhone;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public String getMachineNumber() {
		return machineNumber;
	}

	public void setMachineNumber(String machineNumber) {
		this.machineNumber = machineNumber;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getRegion() {
		return region;
	}

	public void setRegion(String region) {
		this.region = region;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getIsUpdate() {
		return isUpdate;
	}

	public void setIsUpdate(String isUpdate) {
		this.isUpdate = isUpdate;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public MailListDTO(String region, String position, String name, String machineNumber, String mobilePhone,
			String email, String faxNumber, String address, String sex, String isUpdate, String id) {
		super();
		this.region = region;
		this.position = position;
		this.name = name;
		this.machineNumber = machineNumber;
		this.mobilePhone = mobilePhone;
		this.email = email;
		this.faxNumber = faxNumber;
		this.address = address;
		this.sex = sex;
		this.isUpdate = isUpdate;
		this.id = id;
	}

	public MailListDTO() {
		super();
	}

	@Override
	public Uploadable filter(Map<String, List<Uploadable>> map, Set<Uploadable> set, int num) throws Exception {
		/**容纳错误消息的list*/
 		List<Uploadable> mlist = new ArrayList<Uploadable>(Constant.SMALL_CAPACITY);
 		/**容纳正确的，最终用于保存到数据库的数据**/
 		//List<Uploadable> list = new ArrayList<Uploadable>(Constant.SMALL_CAPACITY);
 	    
 		/***
 		 * 过滤掉所有的空格
 		 */
 		String name = StringUtil.trimAll(this.getName());  
 		String mobilePhone = StringUtil.trimAll(this.getMobilePhone()); 
 		String position = StringUtil.trimAll(this.getPosition());      
 		String machineNumber = StringUtil.trimAll(this.getMachineNumber());    
 		String email = StringUtil.trimAll(this.getEmail());   
 		String region = StringUtil.trimAll(this.getRegion());    
 		String faxNumber = StringUtil.trimAll(this.getFaxNumber());   
 		String address = StringUtil.trimAll(this.getAddress());    
 		String id = StringUtil.trimAll(this.getId()); 
 		String sex = StringUtil.trimAll(this.getSex());
 		/**
 	     * 判断是否导入的模板是正确的模板
 	     */
 	    if(num == 1) {
 	    		   if(!CollectionConstant.mail_list_mb.get(0).contains(region)  
 	    			||!CollectionConstant.mail_list_mb.get(1).contains(position)    
 	    			||!CollectionConstant.mail_list_mb.get(2).contains(name)  
 	    			||!CollectionConstant.mail_list_mb.get(3).contains(sex) 
 	    			||!CollectionConstant.mail_list_mb.get(4).contains(machineNumber)      
 	    			||!CollectionConstant.mail_list_mb.get(5).contains(mobilePhone)       
 	    			||!CollectionConstant.mail_list_mb.get(6).contains(email)   
 	    			||!CollectionConstant.mail_list_mb.get(7).contains(faxNumber)       
 	    			||!CollectionConstant.mail_list_mb.get(8).contains(address)   
 		    		||!CollectionConstant.mail_list_mb.get(9).contains(isUpdate)  
 		    		||!CollectionConstant.mail_list_mb.get(10).contains(id)  
 	    			) {
 	    		MsgInfo msg = new MsgInfo(Constant.ERROR_MB,Constant.ERROR_MB,Constant.ERROR_MB,Constant.ERROR_NUM+num);
 				mlist.add(msg);
 				map.put("stop", mlist);
 		    	return null;
 		    }
 	    } else {
 			/***
 			 * 返回处理后的结果数据
 			 */
 			if(!mlist.isEmpty()) {
 				map.put("fail"+num, mlist);
 			} 
 			/***把验证通过的合格数据返回*/
 			this.setAll(name,mobilePhone,position,machineNumber,email,region,isUpdate,id,faxNumber,address,sex);
 			set.add(this);
 			return this;
 	    }
	    return null;
	}

	@Override
	public String flag() throws Exception {
		return this.isUpdate;
	}

	@Override
	public String toString() {
		return "MailListDTO [region=" + region + ", position=" + position + ", name=" + name + ", machineNumber="
				+ machineNumber + ", mobilePhone=" + mobilePhone + ", email=" + email + ", faxNumber=" + faxNumber
				+ ", address=" + address + ", sex=" + sex + ", isUpdate=" + isUpdate + ", id=" + id + "]";
	}

	public void setAll(String name, String mobilePhone, String position, String machineNumber, String email,
			String region, String isUpdate, String id,String faxNumber,String address,String sex) {
		this.name = name;
		this.mobilePhone = mobilePhone;
		this.position = position;
		this.machineNumber = machineNumber;
		this.email = email;
		this.region = region;
		this.faxNumber = faxNumber;
		this.address = address;
		this.sex = sex;
		this.isUpdate = isUpdate;
		this.id = id;
	}

}